package com.woniu;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class Factory {
    private static Map<String, Object> map = new HashMap<>();

    static{
        Properties p = new Properties();
        try {
            p.load(Factory.class.getClassLoader().getResourceAsStream("person.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        Set<String> names = p.stringPropertyNames();
        for (String name : names) {
            String className = p.getProperty(name);
            Object object = null;
            try {
                object = Class.forName(className).newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            map.put(name, object);
        }
    }
    public static Map getMap(){
        return map;
    }
}
